package game

import (
	"server/game/define/verify"
	"server/game/handle"
	"server/game/itypes"
	"server/game/master"
	"server/game/model"
	"server/game/pkg/rank"
	"server/share"
	"server/share/config"
	"server/social"

	"github.com/hwcer/yyds"
	"github.com/hwcer/yyds/context"
	"github.com/hwcer/yyds/options"
	"github.com/hwcer/yyds/players/player"
)

var mod *Module

var (
	_ = master.Register
	_ = handle.Register
	_ = share.Loading
	_ = model.Loading
	_ = itypes.Loading
	_ = verify.Loading
)

func init() {
	mod = &Module{Module: *yyds.New()}
	player.RoleIType = config.ITypeRole
	social.SetEmbed(model.DB())
}

func New() *Module {
	return mod
}

type Module struct {
	yyds.Module
}

func (this *Module) Id() string {
	return options.ServiceTypeGame
}

func (this *Module) Start() (err error) {
	if err = this.Module.Start(); err != nil {
		return err
	}
	if model.Redis != nil {
		err = rank.Start(model.Redis, options.Options.Appid, options.Game.Sid)
	} else {
		return context.Error("Redis未配置,排行榜无法启动")
	}
	return nil
}
